var utils = globalData.infoDs["g_azurlaneUtils"]
var base = globalData.infoDs["g_azurlaneBase"]
var azurCtrl = globalData.infoDs["g_azurlane"]

#精英怪
var elites = ["lingyangzhe", "tansuozhe", "zhiqizhe", "pojuzhe", "zhuijizhe"]

func battleReady():
	if sys.main.batChas == null:return
	var step = sys.main.getStep()
	var bossId = checkBoss()
	if bossId == null:
		insertElites()
	else:
		#插入BOSS
		var batChas = sys.main.batChas
		batChas.shuffle()
		if step < 60:
			var num = batChas.size()/3
			for i in range(num):
				batChas.pop_back()
		batChas.append(bossId)
		sys.main.batChas = batChas

#生成并插入精英怪
func insertElites():
	var step = sys.main.getStep()
	var batChas = sys.main.batChas
	var eliteLv = 2
	if step > 40:
		eliteLv = 3
	if step > 60:
		eliteLv = 4

	if jinJieData.nowLv > 0 and step > 30 and sys.rndPer(min(step*0.1, 8)):
		#随机插入物资船
		batChas.pop_back()
		batChas.append("Wuzichuan")
	elif jinJieData.nowLv > 0 and step > 25 and sys.rndPer(step*0.7) or sys.main.batType == 2:
		#随机插入精英怪
		batChas.pop_back()
		batChas.append("%s-%d"%[sys.rndListItem(elites), eliteLv])
	

	sys.main.batChas = batChas

func chaBonus(cha):
	var step = sys.main.getStep()
	
	if jinJieData.nowLv >= 2 and step > 30:
		doAttrBonus(cha)	

	if jinJieData.nowLv > 2 and step > 50 and cha.lv == 4:
		#角色现代化改造
		var p = (step - 50) * (jinJieData.nowLv - 2) * 0.5
		if sys.rndPer(p) and cha.get("upText1") != null:
			cha.upgraded = 1
			cha.upgrade()
	
	#机组等级提升
	if jinJieData.nowLv > 2 and cha.lv > 2 and (cha.type == sys.CharaClass.CV or cha.type == sys.CharaClass.CVL):
		cha.crewLv = min(10, int(step*0.1))

	if cha.type == sys.CharaClass.BOSS:
		cha.getItems()
		return

func doEquipBonus(cha):
	var step = sys.main.getStep()
	if cha.type == sys.CharaClass.SIREN:
		while cha.items.size() < cha.lv - 1:
			cha.addItem(sys.newItem(itemData.rndGetEquip()))

	if cha.type != sys.CharaClass.SIREN:
		if step > 30 and sys.rndPer((step-30) * jinJieData.nowLv * 0.3) and cha.items.size() < 3:
			cha.addItem(sys.newItem(itemData.rndGetEquip()))
		if step > 30 and sys.rndPer((step-30)) and cha.mainFlag:
			var it = sys.newItem(itemData.rndGetGun())
			it.manualAdd(cha)
		if step > 30 and sys.rndPer((step-30)) and cha.torpFlag:
			var it = sys.newItem(itemData.rndGetTorpedo())
			it.manualAdd(cha)

	if jinJieData.nowLv > 3 and step > 40:
		#重新组织装备
		var addIts = []
		var delIts = []
		for it in cha.items:
			var type = itemData.checkItemType(it)
			if type == "air" and cha.prefer != "air":
				delIts.append(it)
				addIts.append(itemData.rndGetByPrefer(cha.prefer))
			elif type != "air" and cha.prefer == "air":
				delIts.append(it)
				if sys.rndPer(60):
					addIts.append(itemData.rndGetByPrefer(cha.prefer))
				else:
					addIts.append(itemData.rndGetByPrefer("all"))
			elif type != cha.prefer:
				delIts.append(it)
				if sys.rndPer(65):
					addIts.append(itemData.rndGetByPrefer(cha.prefer))
				else:
					addIts.append(itemData.rndGetByPrefer("t"))
		for i in delIts:
			cha.delItem(i)
		for i in addIts:
			cha.addItem(sys.newItem(i))

		#装备升级
		var p = (step - 50) * (jinJieData.nowLv - 3)
		if p > 0:
			for it in cha.items:
				if it.has_method("upgrade") and sys.rndPer(p):
					it.upgrade()
					it.upgraded = true

func doAttrBonus(cha):
	var step = sys.main.getStep()
	cha.attEx.maxHp += (step-20) * 5 * (jinJieData.nowLv - 1)
	cha.attEx.defR += (step-20) * 0.0025 * (jinJieData.nowLv - 1)
	cha.attEx.atkR += (step-20) * 0.0030 * (jinJieData.nowLv - 1)
	if jinJieData.nowLv >= 4:
		cha.attEx.reHp += (step-20) * 0.003
		cha.attEx.penL += (step-20) * 0.003
		cha.attEx.cd += (step-20) * 0.002
		cha.attEx.spd += (step-20) * 0.002
		cha.attEx.dod += (step-20) * 0.5
		cha.attEx.def += (step-20) * 0.5
	cha.upAtt()

func checkBoss():
	var step = sys.main.getStep()
	if sys.main.batType != 2 or jinJieData.nowLv < 2:
		return null
	if step > 20 and step < 30:
		return "GSiren27Ceshizhe"
	if step > 45 and step < 60:
		return "GSiren54Jinghuazhe"
	if step > 75 and step < 90:
		return "GSiren81qingraozhe"
	if step > 100 and step < 115:
		return "GSiren108daixingzhe9"
	if step > 130 and step < 140:
		return "GSiren135hemite"	
	return null


	